package com.gitee.wsl.css.property.sample

import com.gitee.wsl.css.dimensions.Dimension
import com.gitee.wsl.css.dimensions.LinearDimension
import com.gitee.wsl.css.dimensions.css_px
import com.gitee.wsl.css.property.delegate.DynamicDimensionRuleDelegate
import com.gitee.wsl.css.rule.RuleDelegate
import com.gitee.wsl.css.rule.RuleSet

// Basic Box Properties
var RuleSet.bottom by RuleDelegate<LinearDimension?>("bottom")
var RuleSet.clear by RuleDelegate<String?>("clear")
var RuleSet.clip by RuleDelegate<String?>("clip")
var RuleSet.display by RuleDelegate<String?>("display")
var RuleSet.float by RuleDelegate<String?>("float")
var RuleSet.height by DynamicDimensionRuleDelegate("height")
var RuleSet.left by RuleDelegate<LinearDimension?>("left")
var RuleSet.margin by RuleDelegate<Dimension?>("margin")
var RuleSet.marginBottom by RuleDelegate<LinearDimension?>("margin-bottom")
var RuleSet.marginLeft by RuleDelegate<LinearDimension?>("margin-left")
var RuleSet.marginRight by RuleDelegate<LinearDimension?>("margin-right")
var RuleSet.marginTop by RuleDelegate<LinearDimension?>("margin-top")
var RuleSet.maxHeight by DynamicDimensionRuleDelegate("max-height")
var RuleSet.maxWidth by DynamicDimensionRuleDelegate("max-width")
var RuleSet.minHeight by DynamicDimensionRuleDelegate("min-height")
var RuleSet.minWidth by DynamicDimensionRuleDelegate("min-width")
var RuleSet.overflow by RuleDelegate<String?>("overflow")
var RuleSet.overflowX by RuleDelegate<String?>("overflow-x")
var RuleSet.overflowY by RuleDelegate<String?>("overflow-y")
var RuleSet.padding by RuleDelegate<Dimension?>("padding")
var RuleSet.paddingBottom by RuleDelegate<LinearDimension?>("padding-bottom")
var RuleSet.paddingLeft by RuleDelegate<LinearDimension?>("padding-left")
var RuleSet.paddingRight by RuleDelegate<LinearDimension?>("padding-right")
var RuleSet.paddingTop by RuleDelegate<LinearDimension?>("padding-top")
var RuleSet.position by RuleDelegate<String?>("position")
var RuleSet.right by RuleDelegate<LinearDimension?>("right")
var RuleSet.top by RuleDelegate<LinearDimension?>("top")
var RuleSet.visibility by RuleDelegate<String?>("visibility")
var RuleSet.width by DynamicDimensionRuleDelegate("width")
var RuleSet.verticalAlign by RuleDelegate<String?>("vertical-align")
var RuleSet.zIndex by RuleDelegate<Int?>("z-index")

// Flexible Box Layout
var RuleSet.alignContent by RuleDelegate<Alignment?>("align-content")
var RuleSet.alignItems by RuleDelegate<Alignment?>("align-items")
var RuleSet.alignSelf by RuleDelegate<Alignment?>("align-self")
var RuleSet.flex by RuleDelegate<String?>("flex")
var RuleSet.flexBasis by RuleDelegate<String?>("flex-basis")
var RuleSet.flexDirection by RuleDelegate<String?>("flex-direction")
var RuleSet.flexFlow by RuleDelegate<String?>("flex-flow")
var RuleSet.flexGrow by RuleDelegate<String?>("flex-grow")
var RuleSet.flexShrink by RuleDelegate<String?>("flex-shrink")
var RuleSet.flexWrap by RuleDelegate<String?>("flex-wrap")
var RuleSet.justifyContent by RuleDelegate<JustifyContent?>("justify-content")
var RuleSet.order by RuleDelegate<String?>("order")



@JvmInline
value class Alignment(
    val name: String
) {
    override fun toString() = name

    companion object {
        val Start = Alignment("flex-start")
        val End = Alignment("flex-end")
        val Center = Alignment("center")
        val Baseline = Alignment("baseline")
        val Stretch = Alignment("stretch")
    }
}

@JvmInline
value class JustifyContent(
    val name: String
) {
    override fun toString() = name

    companion object {
        val Start = JustifyContent("flex-start")
        val End = JustifyContent("flex-end")
        val Center = JustifyContent("center")
        val SpaceBetween = JustifyContent("space-between")
        val SpaceAround = JustifyContent("space-around")
        val SpaceEvenly = JustifyContent("space-evenly")
    }
}

data class BoxDimension(
    val top: LinearDimension = 0.css_px,
    val right: LinearDimension = top,
    val bottom: LinearDimension = top,
    val left: LinearDimension = right,
) {

    override fun toString(): String = when {
        top == right && top == bottom && top == left -> top.toString()
        top == bottom && left == right -> "$top $right"
        left == right -> "$top $right $bottom"
        else -> "$top $right $bottom $left"
    }
}